﻿using Application.UserService;
using AutoMapper;
using Domain.Entity;
using Domain.Entity.zct;
using Domain.IRepository;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Application.RoleService
{
    public class RoleService : IRoleService
    {
        private readonly IRoleRepository roleRepository;
        private readonly IMapper mapper;

        public RoleService(IRoleRepository roleRepository, IMapper mapper)
        {
            this.roleRepository = roleRepository;
            this.mapper = mapper;

        }

        public Task<int> GetAdd(AddRolesWithPermissionsDto addRolesWithPermissionsDto)
        {
            Role user = mapper.Map<Role>(addRolesWithPermissionsDto.addRoleDto);
            return roleRepository.GetAdd(user,addRolesWithPermissionsDto.permissionIds);
        }

        public Task<List<Role>> GetAll()
        {
            return roleRepository.GetAll();
        }

        public Task<FenYe<Role>> GetAll(FenYe<Role> fenYe, string? Role_code, string? Role_name, int? Role_status)
        {
            return roleRepository.GetAll(fenYe, Role_code, Role_name, Role_status);
        }

        public Task<int> GetDeactivated(int id)
        {
            return roleRepository.GetDeactivated(id);
        }

        public Task<int> GetDelete(int id)
        {
            return roleRepository.GetDelete(id);
        }

        public Task<int> GetEdit(UpdateRolesWithPermissionsDto updateRolesWithPermissionsDto)
        {
            Role role = mapper.Map<Role>(updateRolesWithPermissionsDto.updateRoleDto);
            return roleRepository.GetEdit(role,updateRolesWithPermissionsDto.permissionIds);
        }

        public Task<int> GetEnable(int id)
        {
            return roleRepository.GetEnable(id);
        }

        public Task<Role> GetID(int id)
        {
            return roleRepository.GetID(id);
        }
    }
}
